package com.bkgy.modular.tbprospeed.controller;

import com.bkgy.modular.tbprospeed.entity.dto.ReWeldReq;
import com.bkgy.modular.tbprospeed.service.TbProSpeedService;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.DateUtil;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * Author:Lipeng Zhao
 * Description:
 *
 * @Date:Created In 10:09 2025/10/18
 */
@RestController
@RequestMapping("/tbProSpeed")
public class TbProSpeedController {

    @Autowired
    private TbProSpeedService tbProSpeedService;

    @RequestMapping(value={"/findAll"}, method= RequestMethod.POST)
    public ResultData findDataTbProSpeedData(@RequestBody String data){
        return tbProSpeedService.findDataTbProSpeedData(data);
    };


    @RequestMapping(value={"/speedStatisticsByShift"}, method= RequestMethod.POST)
    public ResultData speedStatisticsByShift(){
        return tbProSpeedService.speedStatisticsByShift();
    };

    @RequestMapping(value={"/speedStatisticsBySteelGrade"}, method= RequestMethod.POST)
    public ResultData speedStatisticsBySteelGrade(){
        return tbProSpeedService.speedStatisticsBySteelGrade();
    };

    @Operation(summary = "酸轧班组报表》钢种重焊率", description = "默认查询前一天的数据")
    @PostMapping("/reWeldRate")
    public ResultData reWeldRate(@RequestBody ReWeldReq req){
        String date = req.getBeginDate();
        String steelGrade = req.getSteelGrade();
        //默认查询上一天时间
        if (StringUtils.isEmpty(date)) {
            date = DateUtil.getDateToString(DateUtil.getBeforDate(), "yyyyMMdd");
        } else {
            Date d = DateUtil.getStringToDate("yyyy-MM-dd", date);
            date = DateUtil.getDateToString(d, "yyyyMMdd");
        }
        return tbProSpeedService.reWeldRate(date, steelGrade);
    }
}
